const http = require("../../models/http")
Page({
  data: {
    value:[],
    checked:false,
  },
  onLoad: function (options) {
    http({
      url:"http://192.168.4.18:8000/cart",
      success:res=>{
        console.log(res.data);
        this.setData({
          value:res.data
        })
      }
    })
  },
  onClick(event){
    this.data.value.forEach(element => {
      if(element.id==event.currentTarget.dataset.id){
        element.isSelected = event.detail;
        // console.log(element.isSelected);
      }
    });
    this.setData({
      value:this.data.value
    })
  },
  onStepper(event){
    /* 1.监听商品数量的改变,得到小计的价格 productCount */
    this.data.value.forEach(element => {
      if(element.id==event.currentTarget.dataset.id){
        element.productCount = event.detail;
      }
    });
    this.setData({
      value:this.data.value
    })
  },
  onSum(event){
    this.data.value.forEach(res=>{
      res.isSelected  = event.detail
    })
    this.setData({
      value:this.data.value
    })
  }
})